package com.ipfsemc.ipfsemc.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.HashMap;

/**
 * 服务器返回给客户端的JSON格式的数据
 */
@ApiModel(value = "JsonData", description = "返回结果类")
@Component
public class JsonData extends HashMap<String, Object> implements Serializable {

    private static final long serialVersionUID = -8855960778711040221L;


    private static final String CODE_KEY = "code";

    @ApiModelProperty(notes = "操作消息",required = true)
    private static final String MESSAGE_KEY = "message";

    @ApiModelProperty(notes = "结果集",required = false)
    private static final String RESULT_KEY = "result";

    @ApiModelProperty(notes = "页码",required = false)
    private static final String PAGE_KEY = "page";

    @ApiModelProperty(notes = "每页行数/页大小",required = false)
    private static final String ROWS_KEY = "rows";

    @ApiModelProperty(notes = "总记录数",required = false)
    private static final String TOTAL_KEY = "total";

//    @ApiModelProperty(notes = "操作代码 0 成功 非0 失败",required = true)
    private Integer code;

    public JsonData() {
        super();
        code=-1;
        this.put(CODE_KEY, code);// 默认操作失败

    }

    public void setCode(Integer code) {
        this.put(CODE_KEY, code);
        this.code=code;
    }

    public Integer getCode() {
        return code;
    }

    public void setMessage(String message) {
        this.put(MESSAGE_KEY, message);
    }

    public void setResult(Object result) {
        this.put(RESULT_KEY, result);
    }


    public void setPage(Integer page) {
        this.put(PAGE_KEY, page);
    }

    public void setRows(Integer rows) {
        this.put(ROWS_KEY, rows);
    }

    public void setTotal(Integer total) {
        this.put(TOTAL_KEY, total);
    }


}
